

import java.util.Vector;

/**
 * @author zz
 * @Date 2022/5/5
 *
 */
public class VectorTest {
    private static Vector<Integer> vector=new Vector<Integer>();

    /**
     * @apiNote Vector安全性测试
     * @param args
     * @exception Exception in thread "Thread-607" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 15
     */
    public static void main(String[] args) {
        while (true){
            for (int i=0;i<10;i++){
                vector.add(i);
            }

            Thread removeThread=new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int i=0;i<vector.size();i++){
                        vector.remove(i);
                    }
                }
            });

            Thread printThread=new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int i=0;i<vector.size();i++){
                        System.out.print(vector.get(i));
                    }
                }
            });

            removeThread.start();
            printThread.start();


            while (Thread.activeCount()>20);
        }
    }
}


